package com.design.singleton;

import java.io.*;

public class SerializableSingletonTest {
    static SerializableSingleton singleton = SerializableSingleton.get();

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(out);
        outputStream.writeObject(singleton);
        outputStream.flush();
        byte[] bytes = out.toByteArray();


        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream);

        Object o = inputStream.readObject();

        System.out.println(o);
        System.out.println(singleton);
    }

}
